<template>
  <div class="app-container">
    <el-card class="content-edit">
      <div slot="header">添加车辆</div>
      <el-form ref="form" :model="form" label-width="140px">
        <el-form-item label="缩略图">
          <div class="image-box">
            <ws-upload-single-img v-model="form['icon']" :path="form['iconUrl']"/>
            <div class="image-remark">
              <div class="remarks"><span class="symbol">⁎</span>注：1. 图片单张大小支持1M一下,超过系统会自动压缩</div>
              <div class="remarks">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. 分辨率要求375px*200px</div>
              <div class="remarks">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3. 支持的图片格式 .jpg、.jpeg、.png、</div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="所属车辆类型">
          <el-select v-model="form['carType']" placeholder="车辆类型">
            <el-option v-for="item in carTypeList" :key="item.id" :value="item['id']" :label="item['name']"/>
          </el-select>
        </el-form-item>
        <el-form-item label="品牌">
          <el-input v-model="form['name']"/>
        </el-form-item>
        <el-form-item label="型号">
          <el-input v-model="form['modelNumber']"/>
        </el-form-item>
        <el-form-item label="车牌号">
          <el-input v-model="form['plateNumber']"/>
        </el-form-item>
        <el-form-item label="颜色">
          <el-input v-model="form['appearance']"/>
        </el-form-item>
        <el-form-item label="动力类型">
          <el-radio-group v-model="form['type']">
            <el-radio :label="1">燃油</el-radio>
            <el-radio :label="2">电动</el-radio>
            <el-radio :label="3">混动</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--<el-form-item label="排量">
          <el-select v-model="form['signInMsgId']" placeholder="排量">
            <el-option value="1.0L" label="1.0L"/>
            <el-option value="1.5L" label="1.5L"/>
            <el-option value="2.0L" label="2.0L"/>
            <el-option value="2.5L" label="2.5L"/>
            <el-option value="其他" label="其他"/>
          </el-select>
        </el-form-item>-->
        <el-form-item label="座位数">
          <el-input v-model="form['seat']" type="number" min="0" style="width: 140px;">
            <span slot="suffix" style="margin-right: 10px;">座</span>
          </el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form['remark']" type="textarea" rows="3"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">保存</el-button>
          <el-button @click="$router.back()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'CustomerServiceTelephone',
    data() {
      return {
        // 车辆类型列表
        carTypeList: [],
        form: {
          // 车辆名称
          name: '',
          // 型号
          modelNumber: '',
          // 车牌号
          plateNumber: '',
          // 所属车辆类型
          carType: '0',
          // 座位数
          seat: '',
          // 图片
          icon: '',
          // 图片地址
          iconUrl: '',
          // 颜色
          appearance: '',
          // 动力类型
          type: '',
          // 备注
          remark: ''
        }
      }
    },
    mounted(){
      this.loadData();
      this.loadCarTypeList();
    },
    methods: {
      // 加载数据
      loadData(){
        (async () => {
          const result = await this.$service.adminApplicationTagGetTagTree();
          if (result.code === 0) {
            //  13
          }
        })();
      },
      // 加载车辆类型列表
      loadCarTypeList(){
        (async () => {
          const result = await this.$service.applicationGetCarTypeList();
          if (result.code === 0) {
            this.carTypeList = result.data;
          }
        })();
      },
      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.loading = true;
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.applicationModifyCar(params);
              this.loading = false;
              if (result.code === 0) {
                this.$message.success('操作成功~');
                this.$router.back();
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
